package model

import "github.com/jinzhu/gorm"

type UserInfo struct {
	*Model
	Username    string `json:"username"`
	SchoolId    string `json:"school_id"`
	Name        string `json:"name"`
	IsMale      int    `json:"is_male"`
	PhoneNumber string `json:"phone_number"`
}

func (u *UserInfo) TableName() string {
	return "user_info"
}

func (u *UserInfo) Create(db *gorm.DB) error {
	return db.Create(u).Error
}

func (u *UserInfo) Get(db *gorm.DB) (*UserInfo, error) {
	user := &UserInfo{}
	err := db.Where("username = ? AND is_del = ?", u.Username, 0).First(user).Error
	return user, err
}

func (u *UserInfo) Update(db *gorm.DB, values map[string]interface{}) error {
	return db.Model(u).Where("username = ? AND is_del = ?", u.Username, 0).Update(values).Error
}
